package com.movitech.mobile.cz.base.supplier.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.movitech.mobile.cz.base.modules.controller.RestReturnResult;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.plugins.Page;
import com.movitech.mobile.cz.base.supplier.entity.SSuppliersInspectionScore;
import com.movitech.mobile.cz.base.supplier.service.SSuppliersInspectionScoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.List;

/**
 * <p>
 * SSuppliersInspectionScore 前端控制器
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-02-28
 */
@RestController
@RequestMapping("/v1/sSuppliersInspectionScore")
@Api(value = "供方考察报告-打分明细基础操作接口", description = "供方考察报告-打分明细基础操作接口")
public class SSuppliersInspectionScoreController {
    @Autowired
    @Qualifier("sSuppliersInspectionScoreService")
    private SSuppliersInspectionScoreService sSuppliersInspectionScoreService;

    @GetMapping("/allList")
    @ApiOperation(
            value = "获取所有供方考察报告-打分明细接口",
            notes = "获取所有供方考察报告-打分明细接口",
            response = SSuppliersInspectionScore.class
    )
    public RestReturnResult list() {
        RestReturnResult restReturnResult = RestReturnResult.success();
        Page<SSuppliersInspectionScore> page = sSuppliersInspectionScoreService.selectPage(new Page<SSuppliersInspectionScore>());
        restReturnResult.setData(page);
        return restReturnResult;
    }

    @PostMapping("/searchList/{pageNumber}")
    @ApiOperation(
            value = "供方考察报告-打分明细列表查询接口",
            notes = "供方考察报告-打分明细列表查询接口",
            response = SSuppliersInspectionScore.class
    )
    public RestReturnResult searchList(@RequestBody SSuppliersInspectionScore sSuppliersInspectionScore,
                @ApiParam(value = "分页页数")@PathVariable Integer pageNumber) {
        RestReturnResult restReturnResult = RestReturnResult.success();
        Page<SSuppliersInspectionScore> page = new Page<>();
        page.setCurrent(pageNumber);
        EntityWrapper wrapper = new EntityWrapper<>();
        wrapper.setEntity(sSuppliersInspectionScore);
        page = sSuppliersInspectionScoreService.selectPage(page,wrapper);
        restReturnResult.setData(page);
        return restReturnResult;
    }

    @GetMapping("/getSSuppliersInspectionScore/{id}")
    @ApiOperation(
            value = "供方考察报告-打分明细对象ID获取接口",
            notes = "供方考察报告-打分明细对对象ID获取接口",
            response = SSuppliersInspectionScore.class
    )
    public RestReturnResult addSSuppliersInspectionScore(@PathVariable String id) {
        RestReturnResult restReturnResult = RestReturnResult.success();
        SSuppliersInspectionScore sSuppliersInspectionScore = sSuppliersInspectionScoreService.selectById(id);
        restReturnResult.setData(sSuppliersInspectionScore);
        return restReturnResult;
    }

    @PostMapping("/add")
    @ApiOperation(
            value = "供方考察报告-打分明细添加接口",
            notes = "供方考察报告-打分明细添加接口",
            response = SSuppliersInspectionScore.class
    )
    public RestReturnResult add(@RequestBody SSuppliersInspectionScore sSuppliersInspectionScore) {
        RestReturnResult restReturnResult = RestReturnResult.success();
        sSuppliersInspectionScoreService.insert(sSuppliersInspectionScore);
        restReturnResult.setData(sSuppliersInspectionScore);
        return restReturnResult;
    }

    @PutMapping("/update")
    @ApiOperation(
            value = "供方考察报告-打分明细更新接口",
            notes = "供方考察报告-打分明细更新接口",
            response = SSuppliersInspectionScore.class
    )
    public RestReturnResult update(@RequestBody SSuppliersInspectionScore sSuppliersInspectionScore) {
        RestReturnResult restReturnResult = RestReturnResult.success();
        sSuppliersInspectionScoreService.updateById(sSuppliersInspectionScore);
        restReturnResult.setData(sSuppliersInspectionScore);
        return restReturnResult;
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(
            value = "供方考察报告-打分明细通过ID删除接口",
            notes = "供方考察报告-打分明细通过ID删除接口",
            response = SSuppliersInspectionScore.class
    )
    public RestReturnResult update(@PathVariable String id) {
        RestReturnResult restReturnResult = RestReturnResult.success();
        sSuppliersInspectionScoreService.deleteById(id);
        return restReturnResult;
    }

    @GetMapping("/getByInspectionId/{inspectionId}")
    @ApiOperation(
            value = "根据报告id供方考察报告-打分明细对象获取接口",
            notes = "根据报告id供方考察报告-打分明细对象获取接口",
            response = SSuppliersInspectionScore.class
    )
    public RestReturnResult getScoreByInspectionId(@PathVariable String inspectionId) {
        RestReturnResult restReturnResult = RestReturnResult.success();
        try {
            EntityWrapper wrapper = new EntityWrapper<>();
            SSuppliersInspectionScore sSuppliersInspectionScore=new SSuppliersInspectionScore();
            sSuppliersInspectionScore.setSuppliersInspectionId(inspectionId);
            wrapper.setEntity(sSuppliersInspectionScore);
            List<SSuppliersInspectionScore> ls=sSuppliersInspectionScoreService.selectList(wrapper);
            restReturnResult.setData(ls);
        }catch (Exception e){
            e.printStackTrace();
            restReturnResult=RestReturnResult.error();
        }
        return restReturnResult;
    }

    

}

